//
// Created by Administrator on 2024/5/20.
//

#include "log.h"

static shared_ptr<logger> g_stdout_logger;
static shared_ptr<logger> g_basic_logger;

void initLog() {
    const char *pattern = "%^%H:%M:%S:%e [%P->%t][%L]%v%$";
    g_basic_logger = basic_logger_mt("file_logger", "logging.log");
    g_basic_logger->set_level(level::trace);
    g_basic_logger->set_pattern(pattern);
    g_stdout_logger = stdout_color_mt("console");
    g_stdout_logger->set_level(level::trace);
    g_stdout_logger->set_pattern(pattern);
}

void log(source_loc loc, level::level_enum lvl, const memory_buf_t &buffer) {
    g_basic_logger->log(loc, lvl, string_view_t(buffer.data(), buffer.size()));
    g_stdout_logger->log(loc, lvl, string_view_t(buffer.data(), buffer.size()));
}